Skip to content

trace: skip JSON lines that are not objects in the cursor readers - #181

Merged
Aaron Li (aaron-jx-li) merged 1 commit into
microsoft:mainfrom
rahul05ranjan:trace/cursor-non-object-lines
Nov 16, 2026
Merged

Aaron Li (aaron-jx-li) merged 1 commit into
microsoft:mainfrom
rahul05ranjan:trace/cursor-non-object-lines

Conversation

@rahul05ranjan

Copy link
Copy Markdown
Contributor

Fixes #180.

cursor_events_to_claude and the prompt-count spool loop called .get on whatever json.loads returned, so a line that parses but is not an object (null, 42, "text", [1, 2]) raised AttributeError and discarded the whole session's trace — the same failure shape #150 fixed for the other 13 readers, missed here because the cursor pair came with the #149 headless work.

The change is the same one-line isinstance(event, dict) guard after json.loads, in both loops. The prompt-count fallback over Cursor's own transcript already had the guard; the spool loop and cursor_events_to_claude did not.

Verification

  • New regression test test_cursor_readers_skip_json_lines_that_are_not_objects: a spool with null, [1, 2], "str", 42 lines around a UserPromptSubmit and a PostToolUse — fails on main@264e7a7 with AttributeError at cursor.py:96, passes with the fix: the count and the reconstructed trace keep exactly the valid records.
  • Full offline suite (python3 -m pytest tests/ -q) green with the fix; standard library only, no dependencies.

cursor_events_to_claude and the prompt-count spool loop called .get on
whatever json.loads returned, so one line that parses but is not an
object (null, 42, "text", [1, 2]) raised AttributeError and discarded
the whole session's trace. microsoft#150 added the isinstance check to the other
13 readers; the cursor pair from microsoft#149 was not in that sweep. Add the
same guard, with a regression test.

Fixes microsoft#180

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>

@aaron-jx-li Aaron Li (aaron-jx-li) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rahul (@rahul05ranjan) Thanks! The code looks correct, but please sign the agreement so we can merge your code.

@rahul05ranjan

Copy link
Copy Markdown
Contributor Author

Thanks Aaron Li (@aaron-jx-li) — the license/cla check is now passing on the current head (agreement signed), with the rest of the CI matrix green. Should be ready for re-review whenever you have a moment.

@aaron-jx-li
Aaron Li (aaron-jx-li) merged commit a970037 into microsoft:main Nov 16, 2026
10 checks passed
@rahul05ranjan

Copy link
Copy Markdown
Contributor Author

Thank you for the merge! Both readers now skip non-object JSON lines consistently.

On a personal note — I'm currently open to new opportunities (Full Stack (PHP, NodeJs, Python) / Data Science / Applied AI / Devtools, based in India). If there's an opening or referral you'd recommend, my inbox is open:
LinkedIn: https://www.linkedin.com/in/rahulswt7/ · GitHub: https://github.com/rahul05ranjan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trace: the cursor readers crash on a JSON line that is not an object

2 participants